﻿<?php

	session_start();

	require_once('../config.php');
	include_once("../database/DataBase.php");
	include_once("../include/function.php");
				
	
	checkLogin();
	
	$search_type = $_POST["search_type"];
	$keyword = $_POST["keyword"];
	
	$database = New DataBase();
	$database->open_connection();
	
	$result = $database->searchUserByLoginIDorEmail($search_type, $keyword, $_SESSION["company_id"], $_SESSION["user_type"]);
?>


<!DOCTYPE html>
<html>
	<head>
	<title>CMS</title>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
		<?php
			include_once("../include/includeHeader.php");
		?>
	</head>
	
	<body>

			<?php
				include_once("../include/top_navigation.php");
			?>
			<div Class="Middle">
				<div class="LeftMenu">
					<?php include_once("../include/left_menu.php"); ?>
				</div>
				<div id="RightContent" >
					<h2>Search User</h2>
					<form name="search_from" method="POST" >
						<table>
						<tr>
							<td>
								<select name="search_type" id="search_type">
									<option value="login_id">Login ID</option>
									<option value="email">Email</option>
								</select>
							</td>
							<td>
								<input type="text" name="keyword" id="keyword" value="">
							</td>
							<td>
								<input type="Submit" name="click_button" value="Search"/>
							</td>
						</tr>
						</table>
						<br/>
						<div id="sarch_result">
							<?php
							if($result != null){
								echo "<table class='dataTable'>";
								echo "<tr class='header'><td>Login ID</td><td>First Name</td><td>First Name</td><td>Email</td><td>Type</td><td>Last Login Date</td><td>Action</td></tr>";
								
								while ($row = mysql_fetch_assoc($result)) {
								echo "<tr>";
								echo "<td>".$row["login_id"]."</td>";
								echo "<td>".$row["firstname"]."</td>";
								echo "<td>".$row["lastname"]."</td>";
								echo "<td>".$row["email"]."</td>";
								echo "<td>".$row["type_id"]."</td>";
								echo "<td>".$row["last_login_date"]."</td>";
								echo "<td><a href=\"user_edit.php?key=".encrypt_string($row["login_id"])."\">Edit</a>/<a href=\"#\" onclick=\"javascript: deactiveUser('".encrypt_string($row["login_id"])."');\" \">Deactive</a></td>";
								echo "</tr>";
								}
								
								echo "</table>";
							}
							else{
								echo "<p>No Result.</p>";
							}
							?>
						</div>
					</form>
				</div>
			</div>
			<?php
				include_once("../include/footer.php");
			?>

		
	</body>
</html>
<?
	$database->close_connection();
?>